home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / Peon / PeonSDK-Win32-1.0.0.exe / {app} / PeonMain / include / CEGUI / CEGUIWindowFactoryManager.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-07  |  12.7 KB  |  405 lines

  1. /************************************************************************
  2.     filename:     CEGUIWindowFactoryManager.h
  3.     created:    22/2/2004
  4.     author:        Paul D Turner
  5.     
  6.     purpose:    Defines interface for WindowFactoryManager class
  7. *************************************************************************/
  8. /*************************************************************************
  9.     Crazy Eddie's GUI System (http://www.cegui.org.uk)
  10.     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
  11.  
  12.     This library is free software; you can redistribute it and/or
  13.     modify it under the terms of the GNU Lesser General Public
  14.     License as published by the Free Software Foundation; either
  15.     version 2.1 of the License, or (at your option) any later version.
  16.  
  17.     This library is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20.     Lesser General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU Lesser General Public
  23.     License along with this library; if not, write to the Free Software
  24.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  25. *************************************************************************/
  26. #ifndef _CEGUIWindowFactoryManager_h_
  27. #define _CEGUIWindowFactoryManager_h_
  28.  
  29. #include "CEGUIBase.h"
  30. #include "CEGUIString.h"
  31. #include "CEGUISingleton.h"
  32. #include "CEGUILogger.h"
  33. #include "CEGUIIteratorBase.h"
  34. #include <map>
  35. #include <vector>
  36.  
  37. #if defined(_MSC_VER)
  38. #    pragma warning(push)
  39. #    pragma warning(disable : 4275)
  40. #    pragma warning(disable : 4251)
  41. #endif
  42.  
  43.  
  44. // Start of CEGUI namespace section
  45. namespace CEGUI
  46. {
  47. /*! 
  48. \brief
  49.     Class that manages WindowFactory objects
  50. */
  51. class CEGUIEXPORT WindowFactoryManager : public Singleton<WindowFactoryManager>
  52. {
  53. public:
  54.     /*!
  55.     \brief
  56.         struct used to hold mapping information required to create a falagard based window.
  57.     */
  58.     struct CEGUIEXPORT FalagardWindowMapping
  59.     {
  60.         String  d_windowType;
  61.         String  d_lookName;
  62.         String  d_baseType;
  63.     };
  64.  
  65.     /*************************************************************************
  66.         Class used to track active alias targets
  67.     *************************************************************************/
  68.     class CEGUIEXPORT AliasTargetStack
  69.     {
  70.     public:
  71.         /*!
  72.         \brief
  73.             Constructor for WindowAliasTargetStack objects
  74.         */
  75.         AliasTargetStack(void) {}
  76.  
  77.  
  78.         /*!
  79.         \brief
  80.             Destructor for WindowAliasTargetStack objects
  81.         */
  82.         ~AliasTargetStack(void) {}
  83.  
  84.  
  85.         /*!
  86.         \brief
  87.             Return a String holding the current target type for this stack
  88.  
  89.         \return
  90.             reference to a String object holding the currently active target type name for this stack.
  91.         */
  92.         const String&    getActiveTarget(void) const;
  93.  
  94.         /*!
  95.         \brief
  96.             Return the number of stacked target types in the stack
  97.  
  98.         \return
  99.             number of target types stacked for this alias.
  100.         */
  101.         uint    getStackedTargetCount(void) const;
  102.  
  103.  
  104.     private:
  105.         friend class WindowFactoryManager;
  106.         typedef std::vector<String>    TargetTypeStack;        //!< Type used to implement stack of target type names.
  107.  
  108.         TargetTypeStack    d_targetStack;        //!< Container holding the target types.
  109.     };
  110.  
  111.  
  112.     /*************************************************************************
  113.         Construction and Destruction
  114.     *************************************************************************/
  115.     /*!
  116.     \brief
  117.         Constructs a new WindowFactoryManager object.
  118.     */
  119.     WindowFactoryManager(void)
  120.     {
  121.         Logger::getSingleton().logEvent((utf8*)"CEGUI::WindowFactoryManager singleton created");
  122.     }
  123.  
  124.  
  125.     /*!
  126.     \brief
  127.         Destructor for WindowFactoryManager objects
  128.     */
  129.     ~WindowFactoryManager(void)
  130.     {
  131.         Logger::getSingleton().logEvent((utf8*)"CEGUI::WindowFactoryManager singleton destroyed");
  132.     }
  133.  
  134.  
  135.     /*************************************************************************
  136.         Public Interface
  137.     *************************************************************************/
  138.     /*!
  139.     \brief
  140.         Return singleton WindowFactoryManager object
  141.  
  142.     \return
  143.         Singleton WindowFactoryManager object
  144.     */
  145.     static    WindowFactoryManager&    getSingleton(void);
  146.  
  147.  
  148.     /*!
  149.     \brief
  150.         Return pointer to singleton WindowFactoryManager object
  151.  
  152.     \return
  153.         Pointer to singleton WindowFactoryManager object
  154.     */
  155.     static    WindowFactoryManager*    getSingletonPtr(void);
  156.  
  157.  
  158.     /*!
  159.     \brief
  160.         Adds a new WindowFactory to the list of registered factories.
  161.  
  162.     \param factory
  163.         Pointer to the WindowFactory to be added to the WindowManager.
  164.  
  165.     \return
  166.         Nothing
  167.     
  168.     \exception NullObjectException        \a factory was null.
  169.     \exception AlreadyExistsException    \a factory provided a Window type name which is in use by another registered WindowFactory.
  170.     */
  171.     void    addFactory(WindowFactory* factory);
  172.  
  173.  
  174.     /*!
  175.     \brief
  176.         Removes a WindowFactory from the list of registered factories.
  177.         
  178.     \note
  179.         The WindowFactory object is not destroyed (since it was created externally), instead it is just removed from the list.
  180.  
  181.     \param name
  182.         String which holds the name (technically, Window type name) of the WindowFactory to be removed.  If \a name is not
  183.         in the list, no error occurs (nothing happens).
  184.  
  185.     \return
  186.         Nothing
  187.     */
  188.     void    removeFactory(const String& name);
  189.  
  190.  
  191.     /*!
  192.     \brief
  193.         Removes a WindowFactory from the list of registered factories.
  194.  
  195.     \note
  196.         The WindowFactory object is not destroyed (since it was created externally), instead it is just removed from the list.
  197.  
  198.     \param factory
  199.         Pointer to the factory object to be removed.  If \a factory is null, or if no such WindowFactory is in the list, no
  200.         error occurs (nothing happens).
  201.  
  202.     \return
  203.         Nothing
  204.     */
  205.     void    removeFactory(WindowFactory* factory);
  206.  
  207.  
  208.     /*!
  209.     \brief
  210.         Remove all WindowFactory objects from the list.
  211.  
  212.     \return
  213.         Nothing
  214.     */
  215.     void    removeAllFactories(void)        {d_factoryRegistry.clear();}
  216.  
  217.  
  218.     /*!
  219.     \brief
  220.         Return a pointer to the specified WindowFactory object.
  221.  
  222.     \param type
  223.         String holding the Window object type to return the WindowFactory for.
  224.  
  225.     \return
  226.         Pointer to the WindowFactory object that creates Windows of the type \a type.
  227.  
  228.     \exception UnknownObjectException    No WindowFactory object for Window objects of type \a type was found.
  229.     */
  230.     WindowFactory*    getFactory(const String& type) const;
  231.  
  232.  
  233.     /*!
  234.     \brief
  235.         Checks the list of registered WindowFactory objects for one which creates Window objects of the specified type.
  236.  
  237.     \param name
  238.         String containing the name (technically, Window type name) of the WindowFactory to check for.
  239.  
  240.     \return
  241.         true if a WindowFactory that creates Window objects of type \a name is registered.  Else, false.
  242.     */
  243.     bool    isFactoryPresent(const String& name) const;
  244.  
  245.  
  246.     /*!
  247.     \brief
  248.         Adds an alias for a current window type.
  249.  
  250.         This method allows you to create an alias for a specified window type.  This means that you can then use
  251.         either name as the type parameter when creating a window.
  252.  
  253.     \note
  254.         You need to be careful using this system.  Creating an alias using a name that already exists will replace the previous
  255.         mapping for that alias.  Each alias name maintains a stack, which means that it is possible to remove an alias and have the
  256.         previous alias restored.  The windows created via an alias use the real type, so removing an alias after window creation is always
  257.         safe (i.e. it is not the same as removing a real factory, which would cause an exception when trying to destroy a window with a missing
  258.         factory).
  259.  
  260.     \param aliasName
  261.         String object holding the alias name.  That is the name that \a targetType will also be known as from no on.
  262.  
  263.     \param targetType
  264.         String object holding the type window type name that is to be aliased.  This type must already exist.
  265.  
  266.     \return
  267.         Nothing.
  268.  
  269.     \exception UnknownObjectException    thrown if \a targetType is not known within the system.
  270.     */
  271.     void    addWindowTypeAlias(const String& aliasName, const String& targetType);
  272.  
  273.  
  274.     /*!
  275.     \brief
  276.         Remove the specified alias mapping.  If the alias mapping does not exist, nothing happens.
  277.  
  278.     \note
  279.         You are required to supply both the alias and target names because there may exist more than one entry for a given
  280.         alias - therefore you are required to be explicit about which alias is to be removed.
  281.  
  282.     \param aliasName
  283.         String object holding the alias name.
  284.  
  285.     \param targetType
  286.         String object holding the type window type name that was aliased.
  287.  
  288.     \return
  289.         Nothing.
  290.     */
  291.     void    removeWindowTypeAlias(const String& aliasName, const String& targetType);
  292.  
  293.     /*!
  294.     \brief
  295.         Add a mapping for a falagard based window.
  296.  
  297.         This function creates maps a target window type and target 'look' name onto a registered window type, thus allowing
  298.         the ususal window creation interface to be used to create windows that require extra information to full initialise
  299.         themselves.
  300.     \note
  301.         These mappings support 'late binding' to the target window type, as such the type indicated by \a targetType need not
  302.         exist in the system until attempting to create a Window using the type.
  303.     \par
  304.         Also note that creating a mapping for an existing type will replace any previous mapping for that same type.
  305.  
  306.     \param newType
  307.         The type name that will be used to create windows using the target type and look.
  308.  
  309.     \param targetType
  310.         The base window type.
  311.  
  312.     \param lookName
  313.         The name of the 'look' that will be used by windows of this type.
  314.  
  315.     \return
  316.         Nothing.
  317.     */
  318.     void addFalagardWindowMapping(const String& newType, const String& targetType, const String& lookName);
  319.  
  320.     /*!
  321.     \brief
  322.         Remove the specified falagard type mapping if it exists.
  323.  
  324.     \return
  325.         Nothing.
  326.     */
  327.     void removeFalagardWindowMapping(const String& type);
  328.  
  329.     /*!
  330.     \brief
  331.         Return whether the given type is a falagard mapped type.
  332.  
  333.     \param type
  334.         Name of a window type.
  335.  
  336.     \return
  337.         - true if the requested type is a Falagard mapped window type.
  338.         - false if the requested type is a normal WindowFactory (or alias), or if the type does not exist.
  339.     */
  340.     bool isFalagardMappedType(const String& type) const;
  341.  
  342.     /*!
  343.     \brief
  344.         Return the name of the LookN'Feel assigned to the specified window mapping.
  345.  
  346.     \param type
  347.         Name of a window type.  The window type referenced should be a falagard mapped type.
  348.  
  349.     \return
  350.         String object holding the name of the look mapped for the requested type.
  351.  
  352.     \exception InvalidRequestException thrown if \a type is not a falagard mapping type (or maybe the type didn't exist).
  353.     */
  354.     const String& getMappedLookForType(const String& type) const;
  355.  
  356. private:
  357.     /*************************************************************************
  358.         Implementation Data
  359.     *************************************************************************/
  360.     typedef    std::map<String, WindowFactory*>    WindowFactoryRegistry;        //!< Type used to implement registry of WindowFactory objects
  361.     typedef std::map<String, AliasTargetStack>    TypeAliasRegistry;        //!< Type used to implement registry of window type aliases.
  362.     typedef std::map<String, FalagardWindowMapping> FalagardMapRegistry;    //!< Type used to implement registry of falagard window mappings.
  363.  
  364.     WindowFactoryRegistry    d_factoryRegistry;            //!< The container that forms the WindowFactory registry
  365.     TypeAliasRegistry        d_aliasRegistry;            //!< The container that forms the window type alias registry.
  366.     FalagardMapRegistry     d_falagardRegistry;         //!< Container that hold all the falagard window mappings.
  367.  
  368. public:
  369.     /*************************************************************************
  370.         Iterator stuff
  371.     *************************************************************************/
  372.     typedef    ConstBaseIterator<WindowFactoryRegistry>    WindowFactoryIterator;
  373.     typedef ConstBaseIterator<TypeAliasRegistry>        TypeAliasIterator;
  374.     typedef ConstBaseIterator<FalagardMapRegistry>      FalagardMappingIterator;
  375.  
  376.     /*!
  377.     \brief
  378.         Return a WindowFactoryManager::WindowFactoryIterator object to iterate over the available WindowFactory types.
  379.     */
  380.     WindowFactoryIterator    getIterator(void) const;
  381.  
  382.  
  383.     /*!
  384.     \brief
  385.         Return a WindowFactoryManager::TypeAliasIterator object to iterate over the defined aliases for window types.
  386.     */
  387.     TypeAliasIterator    getAliasIterator(void) const;
  388.  
  389.  
  390.     /*!
  391.     \brief
  392.         Return a WindowFactoryManager::FalagardMappingIterator object to iterate over the defined falagard window mappings.
  393.     */
  394.     FalagardMappingIterator getFalagardMappingIterator() const;
  395. };
  396.  
  397. } // End of  CEGUI namespace section
  398.  
  399.  
  400. #if defined(_MSC_VER)
  401. #    pragma warning(pop)
  402. #endif
  403.  
  404. #endif    // end of guard _CEGUIWindowFactoryManager_h_
  405.